;(function(w){
	'use strict';
	var bpmUtils={};
	/**
		 * 启动工作流
		 * @param processDefinitionId 流程ID
		 * @param businessKey 业务表单ID
		 * @param formPath 业务表单路径
		 * @param callback 回调函数
		 * @param setting 设置对象
		 * @returns
		 */
	bpmUtils.startProcess = function startProcess(processDefinitionId,businessKey,formPath,callback,setting){
			var defaultSetting={variables:[]};
			var startProcessParam={};
			if (setting) {
				defaultSetting=$.extend(true,defaultSetting,setting);
			}
			startProcessParam.processDefinitionId=processDefinitionId;
			startProcessParam.businessKey=businessKey;
			startProcessParam.variables=[];
			var variablesParam={};
			variablesParam.name="formPath";
			variablesParam.value=formPath;
			startProcessParam.variables.push(variablesParam);
			if (defaultSetting.variables) {
				startProcessParam.variables=startProcessParam.variables.concat(defaultSetting.variables)
			}
			$.ajax({
				type: "POST",
			    url: "../runtime/process-instances",
			    data: JSON.stringify(startProcessParam),
			    contentType: "application/json",
			    success: function(r){
			    	if(callback){
			    		callback();
			    	}
				}
			});
		};
	bpmUtils.getTaskInfo=function(taskId,callback){
		$.ajax({
			type: "GET",
		    url: "../runtime/tasks/"+taskId,
		    contentType: "application/json",
		    success: function(r){
		    	console.info(r)
		    	if(callback){
		    		callback(r);
		    	}
			}
		});
	};
	bpmUtils.getTaskVariables=function(taskId,variableName,callback){
		$.ajax({
			type: "GET",
		    url: "../runtime/tasks/"+taskId+"/variables/"+variableName,
		    contentType: "application/json",
		    success: function(r){
		    	console.info(r)
		    	if(callback){
		    		callback(r);
		    	}
			}
		});
	};
	bpmUtils.getProcessInstanceInfo=function(processInstanceId,callback){
		$.ajax({
			type: "GET",
		    url: "../runtime/process-instances/"+processInstanceId,
		    contentType: "application/json",
		    success: function(r){
		    	console.info(r)
		    	if(callback){
		    		callback(r);
		    	}
			}
		});
	};
	bpmUtils.getProcessInstanceVariables=function(processInstanceId,variableName,callback){
		$.ajax({
			type: "GET",
		    url: "../runtime/process-instances/"+processInstanceId+"/variables/"+variableName,
		    contentType: "application/json",
		    success: function(r){
		    	console.info(r)
		    	if(callback){
		    		callback(r);
		    	}
			}
		});
	};
	w.bpmUtils=bpmUtils;
})(window)



